using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel._Admin.SysTaskV2Vms
{
    public partial class SysTaskV2ListVm : BasePagedListVM<SysTaskV2View, SysTaskV2Searcher>
    {

        protected override IEnumerable<IGridColumn<SysTaskV2View>> InitGridHeader()
        {
            return new List<GridColumn<SysTaskV2View>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.ClassName),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.TaskType),
                this.MakeGridHeader(x => x.StartTime),
                this.MakeGridHeader(x => x.EndTime),
                this.MakeGridHeader(x => x.Repeat),
                this.MakeGridHeader(x => x.IsForever),
                this.MakeGridHeader(x => x.IntervalInSeconds),
                this.MakeGridHeader(x => x.DelaySeconds),
                this.MakeGridHeader(x => x.LastRunTime),
                this.MakeGridHeader(x => x.Cron),
                this.MakeGridHeader(x => x.LastRunResult),
                this.MakeGridHeader(x => x.IsEnable),
                this.MakeGridHeader(x => x.IsRun),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.UpdateTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysTaskV2View> GetSearchQuery()
        {
            var query = DC.Set<SysTaskV2>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.ClassName, x=>x.ClassName)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.TaskType, x=>x.TaskType)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckBetween(Searcher.EndTime?.GetStartTime(), Searcher.EndTime?.GetEndTime(), x => x.EndTime, includeMax: false)
                .CheckEqual(Searcher.Repeat, x=>x.Repeat)
                .CheckEqual(Searcher.IsForever, x=>x.IsForever)
                .CheckEqual(Searcher.IntervalInSeconds, x=>x.IntervalInSeconds)
                .CheckEqual(Searcher.DelaySeconds, x=>x.DelaySeconds)
                .CheckEqual(Searcher.LastRunTime, x=>x.LastRunTime)
                .CheckContain(Searcher.Cron, x=>x.Cron)
                .CheckEqual(Searcher.LastRunResult, x=>x.LastRunResult)
                .CheckEqual(Searcher.IsEnable, x=>x.IsEnable)
                .CheckEqual(Searcher.IsRun, x=>x.IsRun)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .Select(x => new SysTaskV2View
                {
				    ID = x.ID,
                    Name = x.Name,
                    ClassName = x.ClassName,
                    Description = x.Description,
                    TaskType = x.TaskType,
                    StartTime = x.StartTime,
                    EndTime = x.EndTime,
                    Repeat = x.Repeat,
                    IsForever = x.IsForever,
                    IntervalInSeconds = x.IntervalInSeconds,
                    DelaySeconds = x.DelaySeconds,
                    LastRunTime = x.LastRunTime,
                    Cron = x.Cron,
                    LastRunResult = x.LastRunResult,
                    IsEnable = x.IsEnable,
                    IsRun = x.IsRun,
                    CreateTime = x.CreateTime,
                    UpdateTime = x.UpdateTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysTaskV2View : SysTaskV2{

    }
}
